package com.pcbly.web.components.license;

import java.text.SimpleDateFormat;
import java.util.Date;
 
public class LegacyLicense extends License {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6703806472050862506L;
	public static final String EXPIRATION_DATE = "expirationDate";
	public static final String NUM_OF_COPIES = "numCopies";
	public static final String NUM_CLUSTER_MEMBERS = "numClusterMembers";
	public static final String NUM_SEATS = "numSeats";
	private SimpleDateFormat sdf;

	public LegacyLicense(String name, String edition, String version,
			String type, String clientName, String clientCompany,
			String clientUrl, Date expDate, int numCopies, int numClusters,
			long numSeats, String modules[]) {
		sdf = new SimpleDateFormat("MM/dd/yyyy");
		getLicenseData().setName(name);
		getLicenseData().setEdition(edition);
		getLicenseData().setVersion(Version.parseVersion(version));
		getLicenseData().setType(type);
		setClient(clientName, clientCompany, clientUrl);
		getLicenseData().setCreateDate(new Date());
		setExpirationDate(expDate);
		setNumCopies(numCopies);
		setNumClusterMembers(numClusters);
		setNumSeats(numSeats); 
	}

	public String getNumCopies() {
		return (String) getLicenseData().getProperties().get("numCopies");
	}

	public void setNumCopies(int numCopies) {
		getLicenseData().getProperties().put("numCopies", Integer.toString(numCopies));
	}

	public String getNumClusterMembers() {
		return (String) getLicenseData().getProperties().get("numClusterMembers");
	}

	public void setNumClusterMembers(int numClusterMembers) {
		getLicenseData().getProperties().put("numClusterMembers",
				Integer.toString(numClusterMembers));
	}

	public String getNumSeats() {
		return (String) getLicenseData().getProperties().get("numSeats");
	}

	public void setNumSeats(long numSeats) {
		getLicenseData().getProperties().put("numSeats", Long.toString(numSeats));
	}

	public String getNumAgents() {
		return (String) getLicenseData().getProperties().get("numSeats");
	}

	public String getExpirationDate() {
		return (String) getLicenseData().getProperties().get("expirationDate");
	}

	
	public void setExpirationDate(Date expirationDate) {
		String date = expirationDate != null ? sdf.format(expirationDate) : "";
		getLicenseData().getProperties().put("expirationDate", date);
	}

	public void setClient(String name, String company, String url) {
		Client client = new Client(name, company, url);
		getLicenseData().setClient(client);
	}

}
